package com.ruoyi.web.controller.fire;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fire.domain.EMaintenanceUnit;
import com.ruoyi.fire.service.IEMaintenanceUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维保单位Controller
 * 
 * @author ruoyi
 * @date 2025-10-30
 */
@Api(value = "维保单位",tags = "维保单位")
@RestController
@RequestMapping("/fire/unit")
public class EMaintenanceUnitController extends BaseController
{
    @Autowired
    private IEMaintenanceUnitService eMaintenanceUnitService;

    @ApiOperation("维保单位")
    @GetMapping("/allList")
    public AjaxResult allList() {
        return success(eMaintenanceUnitService.list());
    }

    /**
     * 查询维保单位列表
     */
    @PreAuthorize("@ss.hasPermi('system:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(EMaintenanceUnit eMaintenanceUnit)
    {
        startPage();
        List<EMaintenanceUnit> list = eMaintenanceUnitService.selectEMaintenanceUnitList(eMaintenanceUnit);
        return getDataTable(list);
    }

    /**
     * 导出维保单位列表
     */
    @PreAuthorize("@ss.hasPermi('system:unit:export')")
    @Log(title = "维保单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EMaintenanceUnit eMaintenanceUnit)
    {
        List<EMaintenanceUnit> list = eMaintenanceUnitService.selectEMaintenanceUnitList(eMaintenanceUnit);
        ExcelUtil<EMaintenanceUnit> util = new ExcelUtil<EMaintenanceUnit>(EMaintenanceUnit.class);
        util.exportExcel(response, list, "维保单位数据");
    }

    /**
     * 获取维保单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:unit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eMaintenanceUnitService.selectEMaintenanceUnitById(id));
    }

    /**
     * 新增维保单位
     */
    @PreAuthorize("@ss.hasPermi('system:unit:add')")
    @Log(title = "维保单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EMaintenanceUnit eMaintenanceUnit)
    {
        return toAjax(eMaintenanceUnitService.insertEMaintenanceUnit(eMaintenanceUnit));
    }

    /**
     * 修改维保单位
     */
    @PreAuthorize("@ss.hasPermi('system:unit:edit')")
    @Log(title = "维保单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EMaintenanceUnit eMaintenanceUnit)
    {
        return toAjax(eMaintenanceUnitService.updateEMaintenanceUnit(eMaintenanceUnit));
    }

    /**
     * 删除维保单位
     */
    @PreAuthorize("@ss.hasPermi('system:unit:remove')")
    @Log(title = "维保单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eMaintenanceUnitService.deleteEMaintenanceUnitByIds(ids));
    }
}
